package com.ruoyi.project.cms.task.service.serviceImpl;

import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.project.cms.task.domain.Assignment;
import com.ruoyi.project.cms.task.mapper.AssignmentMapper;
import com.ruoyi.project.cms.task.service.AssignmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AssignmentServiceImpl implements AssignmentService {

    @Autowired
    private AssignmentMapper assignmentMapper;

    @Override
    public List<Assignment> findMore(Assignment assignment,String roleName) {

        List<Assignment> assignments = assignmentMapper.selectMore(assignment,roleName);

        return assignments;
    }

    @Override
    public int add(Assignment assignment) {

        String user_name = assignment.getUser_name();
        Assignment one = assignmentMapper.findOne(user_name);
        assignment.setUid(one.getUid());
        return assignmentMapper.insert(assignment);
    }

    @Override
    public Assignment selectOne(int id) {

        System.out.println(id+"service");
        return assignmentMapper.selectOne(id);
    }

    @Override
    public int updateAssignment(Assignment assignment) {
        String user_name = assignment.getUser_name();
        Assignment one = assignmentMapper.findOne(user_name);
        assignment.setUid(one.getUid());
        return assignmentMapper.updateAssignment(assignment);
    }

    @Override
    public int deleteAssignmentByIds(String ids) {
        return assignmentMapper.deleteAssignmentByIds(Convert.toStrArray(ids));
    }

    @Override
    public int deleteAssignmentById(int id) {
        return assignmentMapper.deleteAssignmentById(id);
    }
}
